import axios from "axios";

const state = {
    channels: [],
};
const mutations = {
    setChannels(state, channels) {
        state.channels = channels;
    },
};
const actions = {
    // 1. 定义actions方法，请求数据
    async getChannels(ctx) {
        const {
            data: {
                data: { channels },
            },
        } = await axios("http://geek.itheima.net/v1_0/channels");
        // 2. 通过mutation更新数据

        ctx.commit("setChannels", channels);
    },
};
export default {
    namespaced: true,
    state,
    mutations,
    actions,
};
